//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "AnalyticHaganPricer.h"
using namespace Cephei::QL::Cashflows;
#include <gen/QL/Quote.h>
#include <gen/QL/Cashflows/FloatingRateCoupon.h>
#include <gen/QL/Cashflows/HaganPricer.h>
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Cashflows::CAnalyticHaganPricer::CAnalyticHaganPricer (boost::shared_ptr<QuantLib::AnalyticHaganPricer>& childNative, Object^ owner) : CHaganPricer(CAnalyticHaganPricer::typeid)
{
#ifdef HANDLE
	_phAnalyticHaganPricer = NULL;
#endif
	_ppAnalyticHaganPricer = &childNative;
    _ppHaganPricer = new boost::shared_ptr<QuantLib::HaganPricer> (boost::dynamic_pointer_cast<QuantLib::HaganPricer> (*_ppAnalyticHaganPricer));
}
Cephei::QL::Cashflows::CAnalyticHaganPricer::CAnalyticHaganPricer (QuantLib::AnalyticHaganPricer& childNative, Object^ owner) : CHaganPricer(CAnalyticHaganPricer::typeid)
{
#ifdef HANDLE
	_phAnalyticHaganPricer = NULL;
#endif
	_ppAnalyticHaganPricer = new boost::shared_ptr<QuantLib::AnalyticHaganPricer> (&childNative);
    _ppHaganPricer = new boost::shared_ptr<QuantLib::HaganPricer> (boost::dynamic_pointer_cast<QuantLib::HaganPricer> (*_ppAnalyticHaganPricer));
    _AnalyticHaganPricerOwner = owner;
    _HaganPricerOwner = owner;
}

Cephei::QL::Cashflows::CAnalyticHaganPricer::CAnalyticHaganPricer (CAnalyticHaganPricer^ copy) : CHaganPricer(CAnalyticHaganPricer::typeid)
{
#ifdef HANDLE
	_phAnalyticHaganPricer = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppAnalyticHaganPricer = new boost::shared_ptr<QuantLib::AnalyticHaganPricer> (copy->GetShared());
        _ppHaganPricer = new boost::shared_ptr<QuantLib::HaganPricer> (boost::dynamic_pointer_cast<QuantLib::HaganPricer> (*_ppAnalyticHaganPricer));
    }
}
Cephei::QL::Cashflows::CAnalyticHaganPricer::CAnalyticHaganPricer (PLATFORM::Type^ t) : CHaganPricer(CAnalyticHaganPricer::typeid)
{
#ifdef HANDLE
	_phAnalyticHaganPricer = NULL;
#endif
	if (!t->IsSubclassOf(CAnalyticHaganPricer::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Cashflows::CAnalyticHaganPricer::CAnalyticHaganPricer (QuantLib::Handle<QuantLib::AnalyticHaganPricer>& childNative, Object^ owner)  : CHaganPricer(CAnalyticHaganPricer::typeid)
{
	_phAnalyticHaganPricer = &childNative;
	_ppAnalyticHaganPricer = &static_cast<boost::shared_ptr<QuantLib::AnalyticHaganPricer>>(childNative.currentLink());
    _ppHaganPricer = new boost::shared_ptr<QuantLib::HaganPricer> (boost::dynamic_pointer_cast<QuantLib::HaganPricer> (*_ppAnalyticHaganPricer));
    _AnalyticHaganPricerOwner = owner;
}
Cephei::QL::Cashflows::CAnalyticHaganPricer::CAnalyticHaganPricer (QuantLib::Handle<QuantLib::AnalyticHaganPricer> childNative)  : CHaganPricer(CAnalyticHaganPricer::typeid)
{
	_phAnalyticHaganPricer = &childNative;
	_ppAnalyticHaganPricer = &static_cast<boost::shared_ptr<QuantLib::AnalyticHaganPricer>>(childNative.currentLink());
    _ppHaganPricer = new boost::shared_ptr<QuantLib::HaganPricer> (boost::dynamic_pointer_cast<QuantLib::HaganPricer> (*_ppAnalyticHaganPricer));
}
#endif
#ifdef STRUCT
Cephei::QL::Cashflows::CAnalyticHaganPricer::CAnalyticHaganPricer (QuantLib::AnalyticHaganPricer childNative)  : CHaganPricer(CAnalyticHaganPricer::typeid)
{
#ifdef HANDLE
	_phAnalyticHaganPricer = NULL;
#endif
	_ppAnalyticHaganPricer = new boost::shared_ptr<QuantLib::AnalyticHaganPricer> (new QuantLib::AnalyticHaganPricer (childNative));
    _ppHaganPricer = new boost::shared_ptr<QuantLib::HaganPricer> (boost::dynamic_pointer_cast<QuantLib::HaganPricer> (*_ppAnalyticHaganPricer));
}
#endif

Cephei::QL::Cashflows::CAnalyticHaganPricer::~CAnalyticHaganPricer ()
{
    if (_ppAnalyticHaganPricer != NULL)
    {
	    delete _ppAnalyticHaganPricer;
        _ppAnalyticHaganPricer = NULL;
    }
}
Cephei::QL::Cashflows::CAnalyticHaganPricer::!CAnalyticHaganPricer ()
{
    if (_ppAnalyticHaganPricer != NULL)
    {
	    delete _ppAnalyticHaganPricer;
    }
}
QuantLib::AnalyticHaganPricer& Cephei::QL::Cashflows::CAnalyticHaganPricer::GetReference ()
{
    if (_ppAnalyticHaganPricer == NULL) throw REFNEW NativeNullException ();
	return **_ppAnalyticHaganPricer;
}
boost::shared_ptr<QuantLib::AnalyticHaganPricer>& Cephei::QL::Cashflows::CAnalyticHaganPricer::GetShared ()
{
    if (_ppAnalyticHaganPricer == NULL) throw REFNEW NativeNullException ();
	return *_ppAnalyticHaganPricer;
}
QuantLib::AnalyticHaganPricer* Cephei::QL::Cashflows::CAnalyticHaganPricer::GetPointer ()
{
    if (_ppAnalyticHaganPricer == NULL) throw REFNEW NativeNullException ();
	return &**_ppAnalyticHaganPricer;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::AnalyticHaganPricer>& Cephei::QL::Cashflows::CAnalyticHaganPricer::GetHandle ()
{
	if (_phAnalyticHaganPricer == NULL)
	{
		_phAnalyticHaganPricer = new Handle<QuantLib::AnalyticHaganPricer> (*_ppAnalyticHaganPricer);
	}
	return *_phAnalyticHaganPricer;
}
#endif
bool Cephei::QL::Cashflows::CAnalyticHaganPricer::HasNative () 
{
	return (_ppAnalyticHaganPricer != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

